#!/usr/bin/python
# -*- coding: cp1250 -*-

import sys
import os
import psycopg2

from pepe.utils import u
from pepe.p_sqlpg.pg_import import main as pgim

def main(filesmask): # main() routine is handy if calling from another py scripts
    ''' import text data to PostgreSQL
    '''
    try:
        pgim(filesmask)

    except psycopg2.DataError:
        #psycopg2.DataError: missing data for column "c196"
        print """
        Check delimiters count before running pgload.
        Utilities:
            csv_cntdel
            count_delimiters
            count_delimiters_newextractbad
        """
        # we want to see original error message
        raise

if __name__ == "__main__":
    """
    """
    if len(sys.argv) == 2: 
        main(sys.argv[1])
    else: 
        print "Give file(s) name(mask) that are to be imported to PostgreSQL as parameter."
        os.system('pause')
